package cn.circle.commom.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import cn.circle.commom.dao.impl.BaseDaoImpl;
import cn.circle.commom.model.LoginInfo;

/**
 * 
 * 
 *后台的基础控制器，放置一些公共的方法和成员变量，供后台别的控制器调用，减少代码量
 */
public abstract class BackendBaseController extends BaseDaoImpl{
	
	
	/**
	 * 进入到列表页面
	 * @return
	 */
	protected String index(String view_list,HttpServletRequest request)
	{
		//获取用户可操作的功能菜单
		StringBuffer buttons = new StringBuffer();
		buttons.append("<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" data-options=\"iconCls:'icon-add',plain:true\" onclick=\"append()\">添加</a>");
		buttons.append("<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" data-options=\"iconCls:'icon-remove',plain:true\" onclick=\"edit()\">修改</a>");
		buttons.append("<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" data-options=\"iconCls:'icon-save',plain:true\" onclick=\"removeit()\">移除</a>");
		buttons.append("<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\"	data-options=\"iconCls:'icon-undo',plain:true\" onclick=\"deleteit()\">删除</a>");
		buttons.append("<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\"	data-options=\"iconCls:'icon-search',plain:true\" onclick=\"search()\">查询</a>");

		buttons.append("<script type=\"text/javascript\">");
		buttons.append("function append() {");

		buttons.append("}");

		buttons.append("function edit() {");

		buttons.append("}");

		buttons.append("function removeit() {");

		buttons.append("}");

		buttons.append("function deleteit() {");

		buttons.append("}");

		buttons.append("function search() {");

		buttons.append("}");
		buttons.append("function showOptions(value,rec,index){");
		buttons.append("return \"<input type='button' value='编辑' onclick='alert(\"+rec.name+\")'>\";");
		buttons.append("}");
		buttons.append("</script>");
		
		request.setAttribute("buttons", buttons.toString());
		
		//显示每条记录右边的操作按钮
		StringBuffer rightButton = new StringBuffer("<th data-options=\"field:'_operate',width:180,align:'center',formatter:showOptions\">操作</th>");
		request.setAttribute("rightButton", rightButton.toString());
		
		return view_list;
	}
	
	/**
     * 获取当前登录用户的部门编号
     * @return
     */
    public static Integer getUserDepId(HttpServletRequest request)
    {
        HttpSession session = request.getSession();
        LoginInfo obj = (LoginInfo)session.getAttribute("user");
        return obj.getDepId();
    }
}
